﻿
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[medianamik_GroupPropertyAssociation]') AND type in (N'U'))
BEGIN

ALTER TABLE dbo.medianamik_Group
ALTER COLUMN Name  varchar(256) not null
 
 ALTER TABLE dbo.medianamik_Group ADD CONSTRAINT
            GroupNameUnique UNIQUE NONCLUSTERED
    (
                Name
    )


CREATE TABLE [dbo].[medianamik_GroupPropertyAssociation](
	[GroupPropertyAssociationId] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [varchar](256) NOT NULL,
	[PropertyId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_medianamik_GroupPropertyAssociation] PRIMARY KEY CLUSTERED 
(
	[GroupPropertyAssociationId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]



ALTER TABLE [dbo].[medianamik_GroupPropertyAssociation]  WITH CHECK ADD  CONSTRAINT [FK_GroupPropertyAssociation_Group] FOREIGN KEY([GroupName])
REFERENCES [dbo].[medianamik_Group] ([Name])

ALTER TABLE [dbo].[medianamik_GroupPropertyAssociation] CHECK CONSTRAINT [FK_GroupPropertyAssociation_Group]

ALTER TABLE [dbo].[medianamik_GroupPropertyAssociation]  WITH CHECK ADD  CONSTRAINT [FK_GroupPropertyAssociation_Property] FOREIGN KEY([PropertyId])
REFERENCES [dbo].[medianamik_Property] ([PropertyId])

ALTER TABLE [dbo].[medianamik_GroupPropertyAssociation] CHECK CONSTRAINT [FK_GroupPropertyAssociation_Property]

END